<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Jedlo_model extends CI_Model {
	
	function pridaj()
	{
		$data = array(
			'Nazov_jedla' => $_POST['name'],
			'Hmotnost' => $_POST['weight'],
			'Vyzivova_hmota' => $_POST['value'],
		);
		
		$this->db->insert('Jedlo', $data);
		
		$query = $this->db->select('ID')
			->where('Nazov_jedla', $_POST['name'])
			->get('Jedlo');
				
		$ret = $query->row_array();
		
		foreach(explode("\n", $_POST['items']) as $item) {
			$data = array(
				'Nazov_jedla' => $ret['ID'],
				'Nazov' => $item
			);
			$this->db->insert('Obsahuje', $data);	
		}
	}
}